package com.tencent.wxcloudrun.controller;

import com.tencent.wxcloudrun.config.ApiResponse;
import com.tencent.wxcloudrun.service.ProductService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/products")
public class ProductController {

    @Resource
    private ProductService productService;

    /**
     * 获取所有已发布的商品
     */
    @GetMapping("/list")
    public ApiResponse getAllPublishedProducts() {
        return  ApiResponse.ok(productService.getAllPublishedProducts());
    }

    /**
     * 根据 ID 查询商品详情
     */
    @GetMapping("/{id}")
    public ApiResponse getProductById(@PathVariable Long id) {
        return ApiResponse.ok(productService.getProductById(id));
    }

    /**
     * 关键字搜索商品
     */
    @GetMapping("/search")
    public ApiResponse searchProducts(@RequestParam String keyword) {
        return ApiResponse.ok(productService.searchProducts(keyword));
    }
}
